package co.yixiang.modules.order.cart.entity.vo;


import co.yixiang.modules.goods.entity.domain.YxStoreProduct;
import co.yixiang.modules.order.cart.entity.enums.CartTypeEnum;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Map;

/**
 * 购物车中的产品
 *
 * @author Chopper
 * @since 2020-03-24 10:33 上午
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties(ignoreUnknown = true)
public class CartSkuVO extends CartBase implements Serializable {


    private static final long serialVersionUID = -894598033321906974L;


    private String sn;
    /**
     * 对应的sku DO
     */
    private YxStoreProduct goodsSku;

    @ApiModelProperty(value = "购买数量")
    private Integer num;

    @ApiModelProperty(value = "购买时的成交价")
    private Double purchasePrice;

    @ApiModelProperty(value = "小记")
    private Double subTotal;

    @ApiModelProperty(value = "小记")
    private Double utilPrice;
    /**
     * 是否选中，要去结算 0:未选中 1:已选中，默认
     */
    @ApiModelProperty(value = "是否选中，要去结算")
    private Boolean checked;

    @ApiModelProperty(value = "是否免运费")
    private Boolean isFreeFreight;

    @ApiModelProperty(value = "是否失效 ")
    private Boolean invalid;

    @ApiModelProperty(value = "购物车商品错误消息")
    private String errorMessage;

    @ApiModelProperty(value = "是否可配送")
    private Boolean isShip;

    @ApiModelProperty(value = "积分购买 积分数量")
    private Long point;

    /**
     * @see CartTypeEnum
     */
    @ApiModelProperty(value = "购物车类型")
    private CartTypeEnum cartType;

    /**
     * 在构造器里初始化促销列表，规格列表
     */
    public CartSkuVO(YxStoreProduct goodsSku) {
        this.goodsSku = goodsSku;
        this.checked = true;
        this.invalid = false;
        //默认时间为0，让系统为此商品更新缓存
        this.errorMessage = "";
        this.isShip = true;
        this.purchasePrice = goodsSku.getPrice().doubleValue();
        this.isFreeFreight = false;
        this.utilPrice = goodsSku.getPrice().doubleValue();
    }

    /**
     * 在构造器里初始化促销列表，规格列表
     */
    public CartSkuVO(YxStoreProduct goodsSku, Map<String, Object> promotionMap) {
        this(goodsSku);
//        if (promotionMap != null && !promotionMap.isEmpty()) {
//            this.promotionMap = promotionMap;
//        }
    }


}
